import React, { useEffect, useState } from 'react'
import lyh from './lyh.gif'

export default function Test() {
  const [pos, setPos] = useState({
    x: 0,
    y: 0,
  })

  useEffect(() => {
    // 副作用处理函数
    const mousemove = (e) => {
      console.log('~~')
      setPos({
        x: e.pageX,
        y: e.pageY,
      })
    }
    document.addEventListener('mousemove', mousemove)
    return () => {
      // 清理函数
      document.removeEventListener('mousemove', mousemove)
    }
  }, [])
  return (
    <div>
      <img
        style={{
          position: 'absolute',
          left: pos.x,
          top: pos.y,
          borderRadius: '50%',
        }}
        src={lyh}
        alt=''
      />
    </div>
  )
}
